﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;

namespace OgilvyOne.Utility
{
    public class Util
    {
        public static object getObject(object obj, SqlDataReader dr)
        {
            try
            {
                Type type = obj.GetType();
                PropertyInfo[] piArray = type.GetProperties();
                int i = 0;
                foreach (PropertyInfo pi in piArray)
                {
                    if (!dr.IsDBNull(i++))
                    {
                        string aaa = dr[pi.Name].ToString();
                        pi.SetValue(obj, Convert.ChangeType(dr[pi.Name].ToString(), pi.PropertyType), null);
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
            return obj;
        }
    }
}
